<?php 

/**
 * Joomla! 1.5 component arts_curriculum
 * @package    arts_curriculum
 * @subpackage
 * @author     Chris Borkowski {@link http://www.guggenheim.org}
 * @author     Created on 31-August-2009
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.model');

	/**
	  * Arts_curriculum Component Categories Model
	  *
	  * @package Arts_curriculum
	  */
	  class Arts_curriculumModelCategories extends JModel
	  {
	  /**
	  * Categories data array
	  *
	  * @var array
	  */
	  var $_data = null;
	 /**
	  * Categories total
	  *
	  * @var integer
	  */
	  var $_total = null;
	 /**
	  * Constructor
	  *
	  * @since 1.5
	  */
		
		
		function __construct()
		  {
		  parent::__construct();
		 }
		 /**
		  * Method to get item item data for the category
		  *
		  * @access public
		  * @return array
		  */
		  function getData()
		  {
		  // Lets load the content if it doesn't already exist
		  if (empty($this->_data))
		  {
		  $query = $this->_buildQuery();
		  $this->_data = $this->_getList($query);
		  }
		 return $this->_data;
		  }
		
		
		/**
		  * Method to get the total number of item items for the category
		  *
		  * @access public
		  * @return integer
		  */
		  
		  function getTotal()
		  {
		  // Lets load the content if it doesn't already exist
		  if (empty($this->_total))
		  {
		  $query = $this->_buildQuery();
		  $this->_total = $this->_getListCount($query);
		  }
		  return $this->_total;
		  }
		  function _buildQuery()
		  {
		  $user =& JFactory::getUser();
		  $aid = $user->get('aid', 0);
		 //Query to retrieve all categories that belong under the arts_curriculum section and that are published.
		  $query = 'SELECT cc.*, COUNT(a.id) AS numlinks,'
		  .' cc.id as slug'
		  .' FROM #__categories AS cc'
		  .' LEFT JOIN #__arts_curriculum AS a ON a.catid = cc.id'
		  .' WHERE a.published = 1'
		  .' AND section = \'com_arts_curriculum\''
		  .' AND cc.published = 1'
		  .' AND cc.access <= '.(int) $aid
		  .' GROUP BY cc.id'
		  .' ORDER BY cc.ordering';
		 
		 return $query;
		  }
		  
		  
		 /**
		  * Method to images for the category from the from the article table
		  *
		  * @access public
		  * @return integer
		  */ 
		  
		  
		  	function getImages()
		  	{
		    if (empty($this->_images)) {
				$query ="SELECT ii.ordering, ii.catid, ii.title , ii.crop, cc.id as catID, cc.title as catTITLE, cc.ordering as ordering
						FROM #__arts_curriculum AS ii LEFT JOIN #__categories AS cc ON cc.id = ii.catid WHERE ii.ordering = 1
						GROUP by cc.id
						ORDER by cc.ordering ";
			$this->_images = $this->_getList($query);
			}
		
			return $this->_images;
			}
	
		  
		   
		   /**
		  * Method to get intro AC article 
		  *
		  * @access public
		  * @return integer
		  */ 
		  	
		  	function getIntro()
		  	{
			
			if (empty($this->_intro)) {
			$query = "SELECT main_body FROM #__arts_curriculum WHERE title LIKE 'AC intro'";
			$this->_intro = $this->_getList($query);
			}
		
			return $this->_intro;
			}
	  
		  
  }//the end
  ?>